﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChessSharp.PiecesCode
{
    class GamePieceCollection : ICollection<BasePiece>
    {
        List<BasePiece> InternalPieces;

        public GamePieceCollection()
        {
            this.InternalPieces = new List<BasePiece>();
        }

        /// <summary>
        /// Moves Piece Around Board
        /// </summary>
        /// <param name="From">Piece Starting Point</param>
        /// <param name="To">Piece Destination</param>
        /// <returns>Legality/Success</returns>
        public bool Move(System.Drawing.Point From, System.Drawing.Point To)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Determines if there is a piece at the given location
        /// </summary>
        /// <param name="p">Location in question</param>
        /// <returns>Piece Pressence</returns>
        public bool IsPieceAt(System.Drawing.Point p)
        {
            return this.InternalPieces.Exists(delegate(BasePiece P) { return P.BoardLocation == p; });
        }

        public void Add(BasePiece item)
        {
            this.InternalPieces.Add(item);
        }

        public void Clear()
        {
            this.InternalPieces.Clear();
        }

        public bool Contains(BasePiece item)
        {
            return InternalPieces.Contains(item);
        }

        public void CopyTo(BasePiece[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }

        public int Count
        {
            get { return this.InternalPieces.Count; }
        }

        public int BlackCount
        {
            get
            {
                return this.InternalPieces.FindAll(delegate(BasePiece P) { return P.Owner == System.Drawing.Color.Black; }).Count;
            }
        }

        public int WhiteCount
        {
            get
            {
                return this.InternalPieces.FindAll(delegate(BasePiece P) { return P.Owner == System.Drawing.Color.White; }).Count;
            }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(BasePiece item)
        {
            return this.InternalPieces.Remove(item);
        }

        public IEnumerator<BasePiece> GetEnumerator()
        {
            return this.InternalPieces.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.InternalPieces.GetEnumerator();
        }

        public BasePiece this[int i, int j]
        {
            get
            {
                return this.InternalPieces.Find(delegate(BasePiece p) { return p.BoardLocation == new System.Drawing.Point(i, j); });
            }
        }

        public BasePiece this[System.Drawing.Point P]
        {
            get
            {
                return this[P.X, P.Y];
            }
        }
    }
}
